home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / CONTRSRC.ZIP / SRC / MISC / MATH.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-11-04  |  2.8 KB  |  151 lines

  1. ;************************************************
  2. ;* Math Unit: (C) Type One 1994 / TFL-TDV Prod. *
  3. ;************************************************
  4.  
  5. ;-----------------------------------------
  6. ; Déclaration modèle mémoire
  7. .386
  8. DGROUP GROUP _DATA,_BSS
  9. _TEXT  SEGMENT DWORD PUBLIC USE16 'CODE'
  10.        ASSUME CS:_TEXT,DS:DGROUP
  11. _TEXT  ENDS
  12. _DATA  SEGMENT DWORD PUBLIC USE16 'DATA'
  13. _DATA  ENDS
  14. _BSS   SEGMENT DWORD PUBLIC USE16 'BSS'
  15. _BSS   ENDS
  16. ;-----------------------------------------
  17.  
  18. _DATA SEGMENT
  19.              PUBLIC _Expo
  20.              PUBLIC _ExpoEnd
  21.  
  22. _Expo LABEL WORD
  23.       INCLUDE expo.inc
  24. _ExpoEnd LABEL WORD
  25.  
  26. _DATA ENDS
  27.  
  28. _BSS SEGMENT
  29.              PUBLIC _SinusTbl
  30.  
  31. EVEN
  32. _SinusTbl WORD 1024 DUP(?)  ; zone pour la table sinus (*256) ...
  33. ALIGN 4
  34. EVEN
  35.  
  36. _BSS ENDS
  37.  
  38. _TEXT SEGMENT
  39.              PUBLIC _DoSinusTbl
  40.              PUBLIC _Amorce
  41.              PUBLIC _GetRandom
  42.  
  43. ;#############################################################
  44. ;MakeSinTable creates a 0-1023 integer sine table
  45. ;(c) 1993 by Mikko Reinikainen
  46. ;#############################################################
  47.  
  48. ALIGN
  49. EVEN
  50. _DoSinusTbl PROC FAR
  51.  
  52.     push bp
  53.     mov bp,sp
  54.     pusha
  55.     push es      ; REM: assume DS=_DATA
  56.  
  57.     push ds
  58.     pop es
  59.     mov di,OFFSET _SinusTbl
  60.     mov si,OFFSET _SinusTbl+2*256
  61.     push di
  62.     push si
  63.     mov cx,129 
  64.     sub ax,ax
  65. @@:
  66.     mov [si],ax  ; calculate 
  67.     sub si,2     ; (incremental algorithm like bresenham circle)
  68.     stosw
  69.     mov dx,cx
  70.     shl dx,1
  71.     add ax,dx
  72.     loop @B
  73.  
  74.     pop di
  75.     pop si
  76.     mov cx,256
  77. @@:
  78.     lodsw
  79.     neg ax
  80.     stosw
  81.     loop @B
  82.    
  83.     mov si,OFFSET _SinusTbl
  84.     mov di,OFFSET _SinusTbl+512*2
  85.     mov cx,512
  86. @@:
  87.     lodsw
  88.     sar ax,6 ; *16384/64 = *256
  89.     mov [si-2],ax
  90.     stosw
  91.     loop @B
  92.  
  93.     pop es
  94.     popa
  95.     leave   ; mov sp,bp + pop bp
  96.  
  97.     retf
  98.  
  99. _DoSinusTbl ENDP
  100.  
  101.  
  102. ;***************************
  103. ;* Random number generator *
  104. ;***************************
  105. ALIGN
  106. EVEN
  107. _GetRandom PROC FAR
  108.  
  109. ; Posted by Jare/IGUANA
  110.     
  111.      mov    ax,WORD PTR cs:[Suivant]  
  112.      add    ax,9248h
  113.      ror    ax,3
  114.      mov    WORD PTR cs:[Suivant],ax
  115.      and    ax,7fffh
  116.  
  117.      retf
  118.  
  119. Suivant WORD ?                   ; zone pour nombre aleatoire
  120.  
  121. _GetRandom ENDP
  122.  
  123. ALIGN
  124. EVEN
  125. ;*************************
  126. ;* Init Random Generator *
  127. ;*************************
  128. _Amorce PROC FAR
  129.         
  130.     push   bp
  131.     mov    bp,sp
  132.     push   ax                    ; REM: assume DS=_DATA
  133.  
  134.     xor    al,al
  135.     out    43h,al                ; get timer 0 value
  136.     in     al,40h
  137.     mov    ah,al
  138.     in     al,40h
  139.     mov    WORD PTR cs:[Suivant],ax  ; use it as init value
  140.  
  141.     pop    ax
  142.     leave         ; mov sp,bp + pop bp
  143.  
  144.     retf
  145.  
  146. _Amorce ENDP
  147.  
  148. _TEXT ENDS
  149.  
  150.      END
  151.